package com.lxl.hadoop.nline;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2021/12/25 9:44
 * @Description
 */
public class NLineMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    Text k = new Text();
    IntWritable v = new IntWritable(1);
    protected void map(LongWritable key, Text value,
                       Context context) throws IOException, InterruptedException {
        //输入 key:偏移量, value: 一行内容
        System.out.println("key: " + key.toString());
        String line = value.toString();
        System.out.println("value : "+ line);
        String[] wordArr = line.split(" ");
        for (String s : wordArr) {
            k.set(s);
            context.write(k,v);
        }

    }
}
